import React, { Component } from 'react'
import { connect } from 'react-redux'
import axios from 'axios'

class App extends Component {
  componentDidMount () {
    this.props.getProList()
  }
  render() {
    console.log(this.props.proList)
    return (
      <div>
        {
          this.props.proList.map(item => {
          return <p key = { item.proid }> { item.proname }</p>
          })
        }
      </div>
    )
  }
} 
const mapStateToProps = (state) => {
  return {
    proList: state.getIn(['home', 'proList']) // 第一个元素是模块，第二个是数据
  }
}
export default connect(mapStateToProps,
  dispatch => ({
    getProList () {
      axios.get('http://121.89.205.189:3001/api/pro/list').then(res => {
        console.log(res)
        dispatch({
          type: 'CHANGE_PRO_LIST', // 不需要添加home模块  ‘home/CHANGE_PRO_LIST’
          payload: res.data.data
        })
      })
    }
  })
)(App)
